<template>
  <div>
    <!-- 导航 -->
    <div id="slider" class="slider">
      <nav class="scroll">
        <a
          class="control-item active"
          @click="getPhotoCateList(item.id)"
          v-for="item in cateList"
          :key="item.id"
        >{{ item.title }}</a>
      </nav>
    </div>
    <!-- 图片列表 -->
    <ul class="PhotoList">
      <router-link tag="li" :to="'/home/PhotoInfo/' + item.id" v-for="item in photoList" :key="item.id">
        <img v-lazy.container="item.img_url" />
        <div class="info">
          <h4 class="info-title">{{ item.title }}</h4>
          <div class="info-content">{{ item.zhaiyao }}</div>
        </div>
      </router-link>
    </ul>
  </div>
</template>
<script>
export default {
  data() {
    return {
      cateList: [],
      photoList: []
    };
  },
  created() {
    this.getAllcate();
    this.getPhotoCateList(0);
  },
  methods: {
    getAllcate() {
      this.$http.get("api/getimgcategory").then(result => {
        if (result.data.status === 0) {
          result.data.message.unshift({ id: 0, title: "全部" });
          this.cateList = result.data.message;
        }
      });
    },
    getPhotoCateList(id) {
      this.$http.get("api/getimages/" + id).then(result => {
        if (result.data.status === 0) {
          this.photoList = result.data.message;
        }
      });
    }
  }
};
</script>
<style lang="scss" scope>
.slider {
  widows: 100%;
  line-height: 40px;
  overflow: hidden;
  border-bottom: 1px solid #eee;
  .scroll {
    overflow-x: scroll;
    margin-bottom: -15px;
    padding-bottom: 15px;
    white-space: nowrap;
    .control-item {
      display: inline-block;
      width: 100px;
      text-align: center;
    }
  }
}
.PhotoList {
  list-style: none;
  margin: 0;
  padding: 15px;
  padding-bottom: 0;
  li {
    margin-bottom: 15px;
    border-radius: 2%;
    background-color: #ccc;
    overflow: hidden;
    box-shadow: 0 0 5px #333;
    position: relative;
    img {
      width: 100%;
      vertical-align: middle;
    }
    img[lazy="loading"] {
      width: 40px;
      height: 300px;
      margin: auto;
    }
    .info {
      color: white;
      position: absolute;
      bottom: 0;
      padding: 5px;
      background-color: rgba(0, 0, 0, 0.4);
      max-height: 95px;
      width: 100%;

      .info-title {
        font-size: 15px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }
      .info-content {
        font-size: 13px;
      }
    }
  }
}
</style>